package cc.momas.momall.web.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cc.momas.common.utils.E3Result;
import cc.momas.common.vo.EasyUIDataGridResult;
import cc.momas.momall.po.TbItemParam;
import cc.momas.momall.service.IItemParamService;

@Controller
public class ItemParamController {
	
	@Autowired
	private IItemParamService itemParamSvc;
	
	@RequestMapping(value="/item/param/list")
	@ResponseBody
	private EasyUIDataGridResult queryParam(
			@RequestParam(value="page",defaultValue="1")Integer page,
			@RequestParam(value="row",defaultValue="10")Integer rows
			) {
		EasyUIDataGridResult result = itemParamSvc.getItemParam(page,rows);
		return result;
	}
	
	//根据id查询
	@RequestMapping(value="/rest/item/param/item/query/{id}")
	@ResponseBody
	private E3Result getById(@PathVariable Long id) {
		if(id == null) {return null;}
		TbItemParam p = itemParamSvc.getById(id);
		return E3Result.ok(p);
	}
	//根据分类id查询
	@RequestMapping(value="/item/param/query/itemcatid/{id}")
	@ResponseBody
	public E3Result getByItemCatId(@PathVariable Long id) {
		if(id == null) {return null;}
		List<TbItemParam> ps = itemParamSvc.getByItemCatId(id);
		return E3Result.ok(ps);
	}
	
	//根据id删除
	@RequestMapping(value="/item/param/delete")
	@ResponseBody
	public E3Result batchDeleteById(String ids) {
		int count = itemParamSvc.batchDelete(ids);
		if(count > 0) {
			return E3Result.ok("成功删除" + count + "条记录");
		}
		return E3Result.error("删除失败,未知错误");
	}
}
